package com.zzf.concurrent.example.design.pattern.active.object;

/**
 * @author GaoFeng2017
 * @date 2019/9/11 14:56
 */
public class ActiveObjectFactory {

    private ActiveObjectFactory() {
    }

    private static class ActiveObjectFactoryCreator {
        private static ActiveObjectFactory factory = new ActiveObjectFactory();
    }

    public ActiveObject createActiveObject() {
        ActivationQueue activationQueue = new ActivationQueue();
        SchedulerThread schedulerThread = new SchedulerThread(activationQueue);
        Servant servant = new Servant();
        schedulerThread.start();
        return new ActiveObjectProxy(schedulerThread, servant);
    }

    public static ActiveObjectFactory getInstance() {
        return ActiveObjectFactoryCreator.factory;
    }
}
